package com.ming.sevice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ming.constant.AreaConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.domain.Area;
import com.ming.mapper.AreaMapper;
import com.ming.sevice.AreaService;

/**
 *@Author:何元才
 *@Desc:
 *@data:2021-04-02 15:48
 */
@Service
@CacheConfig(cacheNames = "com.ming.service.impl.AreaServiceImpl")
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService{

    @Autowired
    private AreaMapper areaMapper;

    /**
     * 全查询区域
     *
     * @return
     */
    @Override
    @Cacheable(key = AreaConstant.AREA_PREFIX)
    public List<Area> list() {
        List<Area> list = super.list();
        return list;
    }

    /**
     * 根据父id查询子区域
     *
     * @param pid
     * @return
     */
    @Override
    public List<Area> listByPid(Long pid) {
        return areaMapper.selectList(new LambdaQueryWrapper<Area>()
                .eq(Area::getParentId, pid)
        );
    }
}
